package gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

public class ConfigPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JCheckBox startWithOneCheck = new JCheckBox("Beginn linker Spieler");
	private JCheckBox startWithTwoCheck = new JCheckBox(
			"Beginn rechter Spieler");
	
	private JLabel textField1 = new JLabel("0");
	private JLabel textField2 = new JLabel("0");
	private JLabel textField3 = new JLabel("0");
	
	public void actualizeWinStat(int [] wins){
		textField1.setText(String.valueOf(wins[0]));
		textField2.setText(String.valueOf(wins[1]));
		textField3.setText(String.valueOf(wins[2]));
	}

	public JCheckBox getStartWithTwoCheck() {
		return startWithTwoCheck;
	}

	public void setStartWithTwoCheck(JCheckBox startWithTwoCheck) {
		this.startWithTwoCheck = startWithTwoCheck;
	}

	public JCheckBox getStartWithOneCheck() {
		return startWithOneCheck;
	}

	public void setStartWithOneCheck(JCheckBox startWithOneCheck) {
		this.startWithOneCheck = startWithOneCheck;
	}

	public ConfigPanel(Color backGroundcolor) {
		
		startWithOneCheck.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				if (startWithTwoCheck.isSelected()) {
					startWithTwoCheck.setSelected(false);
				}

			}
		});
		startWithTwoCheck.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				if (startWithOneCheck.isSelected()) {
					startWithOneCheck.setSelected(false);
				}

			}
		});
		JPanel p = new JPanel(new GridLayout(1, 3));
		Box yBox1 = Box.createVerticalBox();
		yBox1.add(startWithOneCheck);
		yBox1.add(Box.createRigidArea(new Dimension(10, 0)));
		yBox1.add(startWithTwoCheck);
		yBox1.add(Box.createRigidArea(new Dimension(15, 0)));
		JLabel nameLabel1 = new JLabel("Spieler1");
		nameLabel1.setFont(new Font("Courier New", Font.ITALIC, 12));
		JLabel nameLabel2 = new JLabel("Unentschieden");
		nameLabel2.setFont(new Font("Courier New", Font.ITALIC, 12));
		JLabel nameLabel3 = new JLabel("Spieler2");
		nameLabel3.setFont(new Font("Courier New", Font.ITALIC, 12));
		textField1 = new JLabel("0");
		textField2 = new JLabel("0");
		textField3 = new JLabel("0");
		Box yBox2 = Box.createHorizontalBox();
		yBox2.add(Box.createRigidArea(new Dimension(10, 0)));
		yBox2.add(nameLabel1);
		yBox2.add(Box.createRigidArea(new Dimension(10, 0)));
		yBox2.add(nameLabel2);
		yBox2.add(Box.createRigidArea(new Dimension(10, 0)));
		yBox2.add(nameLabel3);
		yBox2.add(Box.createRigidArea(new Dimension(10, 0)));
		Box yBox3 = Box.createHorizontalBox();
		yBox3.add(Box.createRigidArea(new Dimension(30, 0)));
		yBox3.add(textField1);
		yBox3.add(Box.createRigidArea(new Dimension(80, 0)));
		yBox3.add(textField2);
		yBox3.add(Box.createRigidArea(new Dimension(80, 0)));
		yBox3.add(textField3);
		yBox3.add(Box.createRigidArea(new Dimension(30, 0)));
		JPanel statsPanel = new JPanel(new GridLayout(2, 1));
		statsPanel.add(yBox2);
		statsPanel.add(yBox3);
		p.add(yBox1);
		Box middleBox = Box.createHorizontalBox();
		middleBox.add(Box.createRigidArea(new Dimension(10, 0)));
		p.add(middleBox);
		p.add(statsPanel);
		Border border = BorderFactory.createEtchedBorder();
		p.setBorder(border);
		// p.setBackground(backGroundcolor);
		add(p);
		setBackground(backGroundcolor);
		setSize(300, 120);
		setBorder(border);
		// setOpaque(false);
	}

}
